﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.spaceinfo
{
    public partial class Add : Web.Admin.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lcs.BLL.sptype bs = new BLL.sptype();
                ddltype.DataSource = bs.GetAllList().Tables[0];
                ddltype.DataTextField = "sptname";
                ddltype.DataValueField = "sptid";
                ddltype.DataBind();

                StringBuilder strWhere = new StringBuilder();
                lcs.BLL.storeinfo bst = new BLL.storeinfo();

                if (Session["login"] != null)
                {
                    DataSet u = (DataSet)Session["login"];

                    if (u.Tables[0].Rows[0]["roles_id"].ToString() == "2")
                    {
                        strWhere.AppendFormat(" uid={0}", u.Tables[0].Rows[0]["user_id"]);

                        ddlstore.DataSource = bst.GetddlList(strWhere.ToString());
                        ddlstore.DataTextField = "sname";
                        ddlstore.DataValueField = "sid";
                        ddlstore.DataBind();
                    }
                }

               
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtspname.Text.Trim().Length == 0)
            {
                strErr += "仓位名称不能为空！\\n";
            }
            
            if (this.txtspadd.Text.Trim().Length == 0)
            {
                strErr += "仓位地址不能为空！\\n";
            }
            if (string.IsNullOrEmpty(this.ddlstore.SelectedValue))
            {
                strErr += "仓库不能为空！\\n";
            }
           

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string spname = this.txtspname.Text;
            int sptype = int.Parse(this.ddltype.SelectedValue);
            string spadd = this.txtspadd.Text;
            int sid = int.Parse(this.ddlstore.SelectedValue);            
            string spdes = this.txtspdes.Text;
            string spremark = this.txtspremark.Text;

            lcs.Model.spaceinfo model = new lcs.Model.spaceinfo();
            lcs.BLL.spaceinfo bll = new lcs.BLL.spaceinfo();
            int i = int.Parse(txtnum.Text);
            if (i == 1)
            {
                model.spname = spname;
                model.sptype = sptype;
                model.spadd = spadd;
                model.sid = sid;
                model.spdes = spdes;
                model.spremark = spremark;



                bll.Add(model);
            }
            else
            {
                for (int j = 0; j < i; j++)
                {
                    model.spname = spname+(j+1).ToString();
                    model.sptype = sptype;
                    model.spadd = spadd;
                    model.sid = sid;
                    model.spdes = spdes;
                    model.spremark = spremark;
                    bll.Add(model);

                }
            }
           
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "List.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}
